<template>
	<view class="padbottom10">
		<!--  -->
		<ben></ben>
		<!--  -->
		<view class="empty" style="margin-top: 300rpx;" v-if="list.length == 0">
			<u-empty mode="data" icon="https://cdn.uviewui.com/uview/empty/data.png">
			</u-empty>
		</view>
		<view class="min30 rad2 background_f column" v-else>
			<!-- <view class="row" style="height: 50px;">
				<view class="size30 col0 flex1 disflex align_item_c just_cont_c"
					:class="tabIndex == 0 ? 'box font600' : 'font500' " @click="tabIndex = 0">
					积分提现记录
				</view>
				<view class="size30 col0 flex1 disflex align_item_c just_cont_c"
					:class="tabIndex == 1 ? 'box_a font600' : 'font500' " @click="tabIndex = 1">
					余额提现记录
				</view>
			</view> -->
			<view class="mintop30 padbottom20" style="border-bottom: 2rpx solid #E7E7E7;" v-for="(item,index) in list"
				:key="index">
				<view class="column min30_rl">
					<view class="row just_cont_spacebet col9 size26 font500">
						{{ item.create_time }}
						<view class="">
							{{tabIndex == 0 ? '积分余额' : '余额' }}
						</view>
					</view>
					<view class="row mintop20 just_cont_spacebet col0 size30 font500 align_item_c">
						{{tabIndex == 0 ? '提现积分' : '提现￥' }}{{ item.score }}
						<view style="color: #FE3C3C;">
							{{tabIndex == 0 ? '' : '￥' }}{{ item.integral }}
						</view>
					</view>
				</view>
			</view>
			<view style="padding: 40rpx 0;"><u-loadmore :status="status" /></view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabIndex: 0,
				user_type: '',
				page: 1,
				status: 'nomore',
				loadmore: [],
				list: [],
			}
		},
		onShow() {
			//当前页面展示的时候他就执行该生命周期
			this.user_type = uni.getStorageSync('user_type');
			this.user_id = uni.getStorageSync('user_id');
			const token = uni.getStorageSync('token');
			if (token) {
				//如果存在token
				this.getOrderList()
				//按正常逻辑来讲 登录成功 我们是不是需要向服务器获取用户的信息？
				//那么我们一起来获取用户信息
			} else {

				uni.showToast({
					title: '您还未登录，正在前往登录',
					icon: 'none'
				})
				setTimeout(function() {
					uni.navigateTo({
						url: "/mypackage/user/login"
					})
				}, 1000)
			}
		},
		onReachBottom() {
			if (this.page < 0) return;
			this.status = 'loading';
			this.page = ++this.page
			this.getOrderList()
			setTimeout(() => {
				console.log(this.loadmore);
				if (this.loadmore.length == 0) this.status = 'nomore';
				else this.status = 'loading';
			}, 1000)
		},
		methods: {
			async getOrderList() {
				var info = {
					page: this.page
				}
				if (this.user_type == 3) {
					info['user_id'] = this.user_id
					info['shop_id'] = 0
				}
				if (this.user_type == 2) {
					info['user_id'] = 0
					info['shop_id'] = this.user_id
				}
				let {
					code,
					message,
					data
				} = await this.$com.fetchGet("shop/payouts_list", info)
				if (code == 200) {
					if (this.page != 1) {
						this.loadmore = data.items
						for (var i = 0; i < data.items.length; i++) {
							this.list.push(data.items[i]); // 加载的数据追加在上一页后面
						}
					} else {
						this.loadmore = data.items
						this.list = data.items
					}
				} else {
					console.log(message);
				}
			},
		}
	}
</script>

<style scoped lang="less">
	.box {
		background-color: #FFAD4C;
		border-radius: 20rpx 20rpx 20rpx 0rpx;
	}

	.box_a {
		background-color: #FFAD4C;
		border-radius: 20rpx 20rpx 0rpx 20rpx;
	}
</style>